package com.qf.lanzhou.shop.api.service.impl;


import com.qf.lanzhou.shop.api.dao.ShowOrderMapper;
import com.qf.lanzhou.shop.api.service.ShowOrderService;
import com.qf.lanzhou.shop.pojo.entity.ParentsOrder;
import com.qf.lanzhou.shop.pojo.entity.SonOrder;
import com.qf.lanzhou.shop.pojo.qo.CommentQO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 是柠檬甜
 * @date 2021/1/14 15:39
 */
@Service
public class ShowOrderServiceImpl implements ShowOrderService {
    @Autowired
    private ShowOrderMapper showOrderMapper;

    @Override
    public List<SonOrder> selectOrder(Long status,Long userId) {
        ParentsOrder parentsOrder = new ParentsOrder();
        parentsOrder.setUserId(userId);
        parentsOrder.setStatus(status);
        List<SonOrder> sonOrders = showOrderMapper.selectOrderByParentStatus(parentsOrder);
        return sonOrders;
    }

    @Override
    public String  changeStatus(Long status, Long id) {
        ParentsOrder parentsOrder = new ParentsOrder();
        parentsOrder.setId(id);
        parentsOrder.setStatus(status);
        int update = showOrderMapper.update(parentsOrder);
        if (update==0){
            throw new RuntimeException("系统繁忙，请稍后再试");
        }
        return "修改成功";
    }

    @Override
    public int addComments(CommentQO commentQO) {
        int i = showOrderMapper.addComment(commentQO);
        return i;
    }
}
